return TRUE;
}
+static gboolean
+copy_prefs_template (GFile *target_dir, GError **error)
+{
+ g_autoptr (GFile) target = NULL;
+ g_autoptr (GFile) source = NULL;
+ g_autofree char *uri = NULL;
+
+ uri = g_strdup ("resource://" TEMPLATES_PATH "/prefs.js");
+ source = g_file_new_for_uri (uri);
+ target = g_file_get_child (target_dir, "prefs.js");
+
+ if (!g_file_copy (source, target, G_FILE_COPY_TARGET_DEFAULT_PERMS, NULL, NULL, NULL, error))
+ return FALSE;
+
+ return TRUE;
+}
+
static gboolean
launch_extension_source (GFile *dir, GError **error)
{
const char *description,
const char *gettext_domain,
const char *settings_schema,
- const char *template)
+ const char *template,
+ gboolean prefs)
{
g_autoptr (GFile) dir = NULL;
g_autoptr (GError) error = NULL;
return FALSE;
}
+ if (prefs && !copy_prefs_template (dir, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ return FALSE;
+ }
+
if (!launch_extension_source (dir, &error))
{
g_printerr ("%s\n", error->message);
g_autofree char *gettext_domain = NULL;
g_autofree char *settings_schema = NULL;
g_autofree char *template = NULL;
+ gboolean prefs = FALSE;
gboolean interactive = FALSE;
gboolean list_templates = FALSE;
GOptionEntry entries[] = {
.arg = G_OPTION_ARG_STRING, .arg_data = &template,
.arg_description = _("TEMPLATE"),
.description = _("The template to use for the new extension") },
+ { .long_name = "prefs",
+ .arg = G_OPTION_ARG_NONE, .arg_data = &prefs,
+ .description = _("Include prefs.js template") },
{ .long_name = "list-templates",
.arg = G_OPTION_ARG_NONE, .arg_data = &list_templates,
.flags = G_OPTION_FLAG_HIDDEN },
return 1;
}
- return create_extension (uuid, name, description, gettext_domain, settings_schema, template) ? 0 : 2;
+ return create_extension (uuid, name, description, gettext_domain, settings_schema, template, prefs) ? 0 : 2;
}
--- /dev/null
+/* prefs.js
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+import Adw from 'gi://Adw';
+import GObject from 'gi://GObject';
+
+import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
+
+const MyPreferencesWidget = GObject.registerClass(
+class MyPreferencesWidget extends Adw.PreferencesGroup {
+ constructor() {
+ super({
+ title: _('Section'),
+ });
+
+ this.add(new Adw.SwitchRow({
+ title: _('Title'),
+ subtitle: _('Subtitle'),
+ active: true,
+ }));
+ }
+});
+
+export default class MyPreferences extends ExtensionPreferences {
+ getPreferencesWidget() {
+ return new MyPreferencesWidget();
+ }
+}
+